<template>
	<view class="">
		<view class="wrap">
			<!-- <image src="/static/aidex/images/1.png" mode="heightFix"></image> -->
			<u-swiper style="width: 100%;" :interval="10000" @change="change" height="1000" :list="list"></u-swiper>
			
		</view>
		<view class="btns">
			<u-button @click="save" class="btn" shape="circle" type="primary" :ripple="true"
				ripple-bg-color="#909399">保存并分享海报</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current :0,
				list: [

				],
			};
		},
		methods: {
			save() {
				let curImg = this.list[this.current]?.image;
				uni.downloadFile({
				    url: curImg, // 替换为实际的图片URL
				    success: (res) => {
				        if (res.statusCode === 200) {
				            // 图片下载成功，res.tempFilePath是图片的本地临时路径
				            this.saveImageToAlbum(res.tempFilePath);
				        }
				    },
				    fail: (err) => {
				        console.error('下载图片失败', err);
				    }
				});

			},
			saveImageToAlbum(filePath) {
			    uni.saveImageToPhotosAlbum({
			        filePath: filePath,
			        success: () => {
			            uni.showToast({
			                title: '图片保存成功',
			                icon: 'success'
			            });
			        },
			        fail: (err) => {
			            console.error('保存图片到相册失败', err);
			            uni.showToast({
			                title: '保存图片失败',
			                icon: 'none'
			            });
			        }
			    });
			},
			change(e){
				console.log(e,55555)
				this.current = e;
			}
		},
		onLoad() {

			this.$u.api
				.userPoster()
				.then((res) => {
					console.log(res?.data?.urls, 888)
					this.list = res?.data?.urls?.map(r => {
						return {
							image: r
						}
					})

				});

		}
	};
</script>

<style lang="scss" scoped>
	.wrap {
		padding: 0 40rpx 200rpx;
		
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100vh;
		// background: red;

	

	}
	.btns {
		position: fixed;
		left: 24rpx;
		right: 24rpx;
		bottom: 70rpx;
		display: flex;
		z-index: 9888;
		align-items: center;
		justify-content: center;
		// margin: 20rpx auto;
		// width: 694rpx;
		height: 90rpx;
		background: #00B9A7;
		border-radius: 52rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 600;
		font-size: 36rpx;
		color: #FFFFFF;
	
		.btn {
			width: 100%;
		}
	
		/deep/ .u-size-default {
			border-radius: 52rpx !important;
			height: 90rpx !important;
			line-height: 90rpx !important;
			font-family: PingFangSC, PingFang SC !important;
			font-weight: 600 !important;
			font-size: 32rpx !important;
		}
	}
</style>